/**
 * Copyright (c) 2011-2014, homeant (homeanter@163.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package xin.homeant.common.utils;

import javax.servlet.ServletContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.context.ServletContextAware;



/**
 * <P>
 * 后台资源拷贝
 * </P>
 * 
 * @author homeant homeanter@163.com
 * @Data 2017年5月22日 下午4:26:04
 */
public class AdminUtil implements InitializingBean, ServletContextAware{
	
	private static Logger _log = LoggerFactory.getLogger(AdminUtil.class);
	
	@Override
	public void setServletContext(ServletContext servletContext) {
		_log.info("===== 开始解压homeant-admin =====");
        String version = PropertiesFileUtil.getInstance("properties/config").get("homeant-admin.version");
        _log.info("homeant-admin.jar 版本: {}", version);
        String jarPath = servletContext.getRealPath("/WEB-INF/lib/homeant-admin-" + version + ".jar");
        _log.info("homeant-admin.jar 包路径: {}", jarPath);
        String resources = servletContext.getRealPath("/") + "/resources/admin";
        _log.info("homeant-admin.jar 解压到: {}", resources);
        JarUtil.decompress(jarPath, resources);
        _log.info("===== 解压homeant-admin完成 =====");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		
	}

}
